package cn.outsourcing.supermarket.common.utils;


import java.security.GeneralSecurityException;

/**
 * 密码密钥工具
 *
 * @author gzkemays
 * @since 2021/1/25 15:48
 */
public class PasswordSecurityUtils {
  /**
   * 加密盐值
   */
  protected static final String SECURITY = "yezijigroup#outsourcing@~!supermarket";

  /**
   * 生成密码
   *
   * @param pwd 原密码
   * @return 加密后的密码
   */
  public static String generatedPassword(String pwd) {
    try {
      return AesUtils.encrypt(pwd, SECURITY);
    } catch (GeneralSecurityException e) {
      e.printStackTrace();
      return null;
    }
  }

  /**
   * 解密密码
   *
   * @param pwd 加过密的密码
   * @return 原密码
   */
  public static String parsePassword(String pwd) {
    try {
      return AesUtils.decrypt(pwd, SECURITY);
    } catch (GeneralSecurityException e) {
      e.printStackTrace();
      return null;
    }
  }

  /**
   * 获取字符串中的字节串
   * @param str 字符串
   * @return 字节串
   */
  private static String getIndex(String str) {
    byte[] bytes = str.getBytes();
    StringBuilder result = new StringBuilder();
    for (byte b : bytes) {
      result.append(b);
    }
    return result.toString();
  }
}
